from typing import Any, Dict, Optional
import time

def create_response(
    data: Any = None, 
    code: int = 200, 
    message: str = "成功"
) -> Dict:
    """
    创建标准的API响应结构
    
    Args:
        data: 响应数据
        code: 响应状态码，默认200表示成功
        message: 响应消息
        
    Returns:
        包含code, data, message和timestamp的标准响应字典
    """
    return {
        "code": code,
        "data": data,
        "message": message,
        "timestamp": str(int(time.time()))
    }

def success_response(data: Any = None, message: str = "成功") -> Dict:
    """
    创建成功响应
    """
    return create_response(data=data, message=message)

def error_response(message: str, code: int = 400, data: Optional[Any] = None) -> Dict:
    """
    创建错误响应
    """
    return create_response(data=data, code=code, message=message)